﻿Imports System.Data.OleDb

Public Class OpenDocument

    Private Sub DocumentBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.DocumentBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DigitalDocumentDataSet)

    End Sub


    Private Sub DocumentBindingNavigatorSaveItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.DocumentBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DigitalDocumentDataSet)

    End Sub

    Private Sub OpenDocument_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DigitalDocumentDataSet.Document' table. You can move, or remove it, as needed.
        Me.DocumentTableAdapter.Fill(Me.DigitalDocumentDataSet.Document)

        Dim strSQL2 As String = "SELECT * FROM Document "


        Try
            Using adapter2 As New OleDbDataAdapter(strSQL2, My.Settings.DigitalDocumentConnectionString)


                Dim ds2 As New DataSet
                adapter2.Fill(ds2, "Document")


                Me.OpenListBox.DataSource = ds2.Tables("Document")
                Me.OpenListBox.ValueMember = "DId"
                Me.OpenListBox.DisplayMember = "Title"


            End Using
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim strSQL1 As String = "SELECT Template FROM Document WHERE DId =" & Me.OpenListBox.SelectedValue.ToString


        Form1.Did = Me.OpenListBox.SelectedValue.ToString

          Try
            Using adapter2 As New OleDbDataAdapter(strSQL1, My.Settings.DigitalDocumentConnectionString)


                Dim ds2 As New DataSet
                adapter2.Fill(ds2, "Document")

                Dim dt As New DataTable
                dt = ds2.Tables("Document")


                Form1.Form1TempText.Text = dt(0)(0)






            End Using
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try




        Form1.action = "Open"
        Form1.actions()

        Me.Close()

    End Sub


 
End Class